package chapter24;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * @author lzy
 * @version v1.0
 * Create DateTime: 2019/2/27 22:05
 */
public class ConfigurableStrategyDemo {
    public static void main(String[] args) throws IOException {
        InputStream inputStream = ClassLoader.getSystemClassLoader().getResourceAsStream("config.properties");
        Properties properties = new Properties();
        properties.load(inputStream);
        String service = properties.getProperty("service");
        try {
            Class<?> cls = Class.forName(service);
            IService service1 = (IService) cls.newInstance();
            service1.action();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        }
    }
}
